﻿using System;
using System.ComponentModel;
using System.Reflection;

namespace NTQOnlineExam.Services.Infrastructure.Utility
{
    public static class EnumExtensions
    {
        public static string ToDescriptionString(this Enum value)
        {
            if (value == null) throw new ArgumentNullException("value");
            Type type = value.GetType();
            FieldInfo fieldInfo = type.GetField(Enum.GetName(type, value));
            var descriptionAttribute = (DescriptionAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute));

            if (descriptionAttribute != null) return descriptionAttribute.Description;
            return value.ToString();
        }

     
    }
}